/**
 * @Auther: MFM
 * @Date: 2022/3/14 - 03 - 14 - 18:33
 * @version: 1.0
 */

public class DoubleArrayQueue<E> {
    /*
    * 双向队列
    * */
    //底层数组
    private ArrayDemo<E> array;

    //以左为队首 入队
    public void enqueueL(E e) throws Exception {
        array.addFirst(e);
    }

    //以右为队首 入队
    public void enqueueR(E e) throws Exception {
        array.addLast(e);
    }

    //以左左为队首 出队
    public E dequeueL()  throws Exception{
        if (getSize()==0){
            return null;
        }
        return array.deleteData(array.getSize());
    }

    //以右为队首 出队
    public E dequeueR()  throws Exception{
        if (getSize()==0){
            return null;
        }
        return array.deleteData(0);
    }

    //以左为队首 查看队首元素
    public E getFrontL() throws Exception{
        return array.seeData(0);
    }

    //以右为队首 查看队首元素
    public E getFrontR() throws Exception{
        return array.seeData(array.getSize());
    }

    //获得队列元素
    public int getSize()  throws Exception{
        return array.getSize();
    }

    //判断是否为空
    public boolean isEmpty()  throws Exception{
        return array.getSize()==0;
    }

    @Override
    public String toString() {
        return "DoubleArrayQueueDemo{" +
                "array=" + array +
                '}';
    }

}
